package cn.com.infohold.smartcity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.orm.SugarContext;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;

import java.io.File;

import cn.com.infohold.smartcity.data.XmlConfig;
import cn.com.infohold.smartcity.parent.ParentApplication;
import cn.jpush.android.api.JPushInterface;
import common.utils.AssetsUtils;
import common.utils.FileUtils;
import library.utils.ApkUtils;
import library.utils.Logger;
import library.utils.Utils;

/**
 * Created by apple on 2017/3/16.
 */

public class MainApplication extends ParentApplication {


    @Override
    public void onCreate() {
        super.onCreate();
        ZXingLibrary.initDisplayOpinion(this);
        FileUtils.init(this);
//        InitDataBase(this);
//        MapSDK.setProvider(new MyMapboxProvider());
//        MapSDK.getProvider().init(this);
        SugarContext.init(this);
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        //MapUtils.init(this, XmlConfig.getInstance().getArcGisLicense());

        if (Utils.isRemoteProcess(this))
            return;
//        DaemonConfig config = new DaemonConfig(MyDaemonService.class);
//        config.setUseNative(true);
//        config.setUseJobService(false);
//        config.setUseOnePixelActivity(false);
//        DaemonHelper.register(this, config);

//        Logger.debug(ApkUtils.isInstalled(this, "internal.assistant.develop"));
    }

    private void InitDataBase(Context context) {
        try {
            Bundle metaBundle = ApkUtils.getMetaDataFromApplication(context);
            if (metaBundle == null)
                return;
            String metaDB = metaBundle.getString("DATABASE");
            if (TextUtils.isEmpty(metaDB))
                return;
            File file = getDatabasePath(metaDB);
            if (!file.exists()) {
                AssetsUtils.obtain(context).copyAssetsFile("database/" + metaDB, file, false);
            }
        } catch (Exception e) {
            Logger.debug(e);
        }
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        SugarContext.terminate();
    }
}
